package com.atguigu.ascii;

import org.junit.Test;

import java.util.Base64;

public class AsciiDemo {
    public static void main(String[] args) {
        //单个字符传唤ASCII码
        char a = 'a';
        System.out.println((int) a);
        System.out.println();
        //字符串转换成ascii码

        String string = "asdsdsd";
        char[] chars = string.toCharArray();
        for (char aChar : chars) {
            System.out.print((int) aChar);
        }
    }



    /**
     * 把 hello world 往右边移动3位
     */
    public static String encryptKaiser(String srcFile,int key){
        String str = "hello world ";
        //int key = 3;
        char[] chars = srcFile.toCharArray();
        StringBuilder sb = new StringBuilder();

        for (char aChar : chars) {
            sb.append((char)((int)aChar + key));
        }
        //System.out.println(sb.toString());
        return sb.toString();
    }
    /**
     * decryptKaiser
     */

    public static String decryptKaiser(String input,int key){
        //String encryptKaiser = encryptKaiser(input,key);

        char[] chars = input.toCharArray();
        StringBuilder sb = new StringBuilder();

        for (char aChar : chars) {
            sb.append((char)((int)aChar - key));
        }
        //System.out.println(sb.toString());
        return sb.toString();
    }

}
